package 数组;

public class Test2 {
    public static void main(String[] args) {

        printArray(4);

    }

    public static void printstart(int arr[][])
    {
        int i = 0;
        int j = 0;
        for(i = 0; i < arr.length; i++)
        {
            for(j = 0;j < arr.length; j++)
            {
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }
    }
    public static void printArray(int n)
    {
        int arr [][] = new int[n][n];
        int i = 0;
        int j = 0;
        int count = 1;
        for(i = 0;i < n; i++)
        {
            for(j=0; j < n; j++)
            {
                arr[i][j] = count;
                count++;
            }

        }
        printstart(arr);
        System.out.println("----------------------");
        for(i = 0;i<n;i++)
        {
            for(j = 0;j<n;j++)
            {
                int a = (int)(Math.random() * arr.length);
                int b = (int)(Math.random()* arr.length);
                int tmp = arr[a][b];
                arr[a][b] = arr[i][j];
                arr[i][j] = tmp;

            }

        }
        printstart(arr);
    }


}
